﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using eCRAM.Dao;
using eCRAM.Model;
using Microsoft.Practices.Unity;

namespace eCRAM.Bll
{
    public class UserManager : IUserManager
    {
        [Dependency]
        public IRepository <User> UserRepository { get; set; }

       /* public IQueryable<User> GetAll()
        {
            return UserRepository.GetAll();
        }

        public void Create(User t)
        {
            UserRepository.Create(t);
        }

        public void Update(User t)
        {
            UserRepository.Update(t);
        }

        public void Delete(User t)
        {
            UserRepository.Delete(t);
        }

        public User GetById(Guid id)
        {
            return UserRepository.GetById(id);
        }

        public int GetCount()
        {
            return UserRepository.GetCount();
        }

        public IQueryable<User> GetTop(int start, int limit)
        {
            return UserRepository.GetTop(start,limit);
        }

        public void SubmitChanges()
        {
            UserRepository.SubmitChanges();
        }
         */

        public User GetUser(string userName, string password)
        {
            IQueryable<User> list = UserRepository.GetAll();
            
                //FIXME I guess the password is not encrypted...
                return (list.Where(c => c.UserName.Equals(userName) && c.Password.Equals(password))).FirstOrDefault<User>();
           
        }

        public User GetUser(string userName)
        {
             IQueryable<User> list = UserRepository.GetAll();
            return list.Where(c => c.UserName.Equals(userName)).FirstOrDefault<User>();
        }


        public bool ValidateUser(string userName, string password)
        {
            throw new NotImplementedException();
        }

        public void CreateUser(string userName, string password, string email)
        {
            throw new NotImplementedException();
        }

        public bool ChangePassword(string userName, string oldPassword, string newPassword)
        {
            throw new NotImplementedException();
        }
    }
}
